package com.hz.ruoyifarmbase.farm.controller;

import com.hz.ruoyifarmbase.basedata.domain.AgrGermBreed;
import com.hz.ruoyifarmbase.basedata.service.IAgrGermBreedService;
import com.hz.ruoyifarmbase.baseinfo.domain.AgrBasePlots;
import com.hz.ruoyifarmbase.baseinfo.service.IAgrBasePlotsService;
import com.hz.ruoyifarmbase.farm.domain.AgrBaseBatch;
import com.hz.ruoyifarmbase.farm.domain.vo.AgrBatchBreedVo;
import com.hz.ruoyifarmbase.farm.service.AgrBaseBatchService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 侯文波
 * @date 2025/3/7 10:21
 * @description:
 */
@RestController
@RequestMapping("/batch")
public class AgrBaseBatchController extends BaseController {

    @Autowired
    private AgrBaseBatchService agrBaseBatchService;
    @Autowired
    private IAgrBasePlotsService iAgrBasePlotsService;
    @Autowired
    private IAgrGermBreedService iAgrGermBreedService;

    @RequiresPermissions("farm:batch:list")
    @GetMapping("/list")
    public TableDataInfo list(AgrBatchBreedVo agrBatchBreedVo){
        startPage();
        List<AgrBatchBreedVo> list = agrBaseBatchService.selectAgrBatchBreedList(agrBatchBreedVo);
        return getDataTable(list);
    }
    /**
     * @param
     * @return: com.ruoyi.common.core.web.page.TableDataInfo
     * @Author: zjk
     * @Date: 2025/3/11 10:54
     * @Description: 地块下拉列表
     */

    @RequiresPermissions("farm:batch:list")
    @GetMapping("/listPlots")
    public TableDataInfo plotsListSelect(AgrBasePlots agrBasePlots){
        List<AgrBasePlots> list = iAgrBasePlotsService.selectAgrBasePlotsList(agrBasePlots);
        return getDataTable(list);
    }
    @RequiresPermissions("farm:batch:list")
    @GetMapping("/listBreed")
    public TableDataInfo BreedListSelect(){
        List<AgrGermBreed> list = iAgrGermBreedService.selectAgrGermBreedList(null);
        return getDataTable(list);
    }

    @RequiresPermissions("farm:batch:add")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody AgrBaseBatch agrBaseBatch){
        return AjaxResult.success(agrBaseBatchService.insertAgrBaseBatch(agrBaseBatch));
    }

    @RequiresPermissions("farm:batch:update")
    @PostMapping("/update")
    public AjaxResult update(@RequestBody AgrBatchBreedVo agrBaseBatchvo){

        return AjaxResult.success(agrBaseBatchService.updateAgrBaseBatch(agrBaseBatchvo));
    }

    @RequiresPermissions("farm:batch:delete")
    @DeleteMapping("/delete/{batchId}")
    public AjaxResult delete(@PathVariable Long batchId){
        return AjaxResult.success(agrBaseBatchService.deleteAgrBaseBatch(batchId ));
    }


    @GetMapping("/mature")
    @CrossOrigin(origins = "*")
    public List<Map<String, Object>> getBatchMature() {
        return agrBaseBatchService.getBatchMature();
    }



}
